<!--项目动态列表-->
<template>
  <div>
    <trends :Posts="list"></trends>
    <bottoms></bottoms>
  </div>
</template>

<script>
  import trends from '@/components/project/trends'
  import bottoms from '@/components/reachBottom/index'
  export default {
        name: "trends",
      components: {
        trends,
        bottoms
      },
      data(){
        return{
          id: '',
          list:[],
          loadingEnd:{
            moduleOne: false,
          },
          totalPage: 1,
          currentPage: 1
        }
      },
      methods:{
        // 获取项目动态
        getProjectInfo(){
          this.$ajax
            .post(this.$api.getProjectInformationInfo
              , {project_id: this.id, page_size: 10, page: this.currentPage})
            .then(res => {
              this.list.push(...res.data);
              this.loadingEnd.moduleOne = true
              this.totalPage = res.total_page
              if(res.total_count === 0){
                this.$store.dispatch("changeIsEmpty", true);
              } else {
                this.$store.dispatch("changeIsEmpty", false);
              }
            })
            .catch(err => {
              this.loadingEnd.moduleOne = true
              ﻿uni.showToast({
                title: err,
                icon: 'none',
                duration: 2000
              })
            });
        },
        viewLoad(){
          this.$store.dispatch("changeIsMore", false);
          this.$store.dispatch("changeIsEnd", false);
          this.$store.dispatch("changeIsEmpty", false);
          this.currentPage = 1
          this.list = []
          this.loadingEnd = {
            moduleOne: false,
          };
          ﻿uni.showLoading({
            title: '加载中',
            mask: true
          });
          this.getProjectInfo();
        }
      },
    computed:{
      hideLoading(){
        if(this.loadingEnd.moduleOne){
          setTimeout(function(){
            ﻿uni.hideLoading()
            }, 800)
        }
      }
    },
    onPullDownRefresh(){
      this.viewLoad()
      ﻿uni.stopPullDownRefresh() //停止下拉刷新
    },
    onReachBottom(){
      if(this.totalPage > this.currentPage){
        this.$store.dispatch("changeIsMore", true);
        this.$store.dispatch("changeIsEnd", false);
        this.currentPage++
        this.getMovieList();
      } else {
        this.$store.dispatch("changeIsEnd", true);
        this.$store.dispatch("changeIsMore", false);
      }
    },
    onLoad(res){
      this.id = res.id
      this.viewLoad()
    }
    }
</script>

<style scoped>

</style>
